﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using DigiLib;
using System.Web.UI.HtmlControls;
public partial class controls_admin_GuestLog : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadData();
        }
    }
    public void LoadData()
    {
        try
        {
            base.bindRepeater(rptData, BO_portal_guest_log.SelectAdmin(string.Empty, base.Cur_page(pagerContainer), base.Page_size), divMessage, pagerContainer);
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi: <br />" + ex.Message);
        }
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        try
        {
            bool flag = false;
            for (int i = 0; i < rptData.Items.Count; i++)
            {
                var chkBox = rptData.Items[i].FindControl("chkBox") as HtmlInputCheckBox;
                if (chkBox != null && chkBox.Checked)
                {
                    flag = true;
                    HiddenField hdfURL = (HiddenField)rptData.Items[i].FindControl("hdfURL");
                    SqlUtils.ExecuteNonQuery("DELETE FROM dbo.portal_guest_log WHERE GUEST_ID = " + chkBox.Value + " AND URL_ID = " + hdfURL.Value);
                }
            }

            if (!flag)
            {
                Javascripts.Alert(Page, "Phải chọn ít nhất lượt truy cập!");
                return;
            }
            LoadData();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi hệ thống", "Phát hiện lỗi sau: " + ex.Message);
        }
    }
}
